package io.adrainty.bolee.insurance.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.framework.mybatis.utils.MybatisUtil;
import io.adrainty.bolee.insurance.models.entity.BannerEntity;
import io.adrainty.bolee.insurance.service.IBannerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>BannerController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description 导航信息
 * @since 2025/8/18 16:05:14
 */

@Tag(name = "导航信息")
@RestController
@RequestMapping("banner")
public class BannerController {

    @Resource
    private IBannerService bannerService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询")
    public ResultDTO<IPage<BannerEntity>> page(@PathVariable("pageNum") Integer pageNum,
                                               @PathVariable("pageSize") Integer pageSize,
                                               @RequestBody BannerEntity param) {
        IPage<BannerEntity> bannerVOs = bannerService.pageBanner(pageNum, pageSize, param);
        return ResultDTOUtil.success(bannerVOs);
    }

    @PutMapping
    @Operation(summary = "保存Banner")
    public ResultDTO<BannerEntity> createBanner(@RequestBody BannerEntity bannerVO) {
        BannerEntity bannerVOResult = bannerService.saveBanner(bannerVO);
        return ResultDTOUtil.success(bannerVOResult);
    }

    @PatchMapping
    @Operation(summary = "修改Banner")
    public ResultDTO<Boolean> updateBanner(@RequestBody BannerEntity bannerVO) {
        Boolean bannerVOResult = bannerService.updateBanner(bannerVO);
        return ResultDTOUtil.success(bannerVOResult);
    }

    @DeleteMapping
    @Operation(summary = "删除Banner")
    public ResultDTO<Boolean> deleteBanner(@RequestBody BannerEntity bannerVO) {
        Boolean bannerVOResult = bannerService.deleteBanner(MybatisUtil.convertCheckIds(bannerVO.getCheckedIds()));
        return ResultDTOUtil.success(bannerVOResult);
    }

}
